﻿using System;
using System.Linq.Expressions;

namespace RexToy
{
    public static class MaybeNullExtension
    {
        public static R GetIfNotNull<T, R>(this T x, Func<T, R> func)
        {
            if (x != null)
                return func(x);
            else
                return default(R);
        }

        public static R GetIfNotNull<T, R>(this T x, Func<T, R> func, R fallback)
        {
            if (x != null)
                return func(x);
            else
                return fallback;
        }
    }
}
